package com.longfor.dragonshard.config;

import com.longfor.daenerys.config.LFProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author chi.zhang
 * @version v1.0
 * @create 2017-12-16 下午12:27
 **/
@Configuration
@EnableCaching
public class RedisCacheConfig extends CachingConfigurerSupport {
    private final Logger logger = LoggerFactory.getLogger(RedisCacheConfig.class);
    @Autowired
    private LFProperties lfProperties;

    @Bean
    public CacheManager cacheManager(RedisTemplate redisTemplate) {
        logger.info("==== Creating CacheManager ====");
        RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
        rcm.setDefaultExpiration(lfProperties.getCache().getDefaultExpiration());
        return rcm;
    }


}
